<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Computes the Metropolis-Hastings heuristic edge weights</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/graph_laplacian/html/mh.html">
<link rel="stylesheet" href="../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Computes the Metropolis-Hastings heuristic edge weights</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
Text output
&nbsp;&nbsp;&nbsp;&nbsp;
Plots
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="keyword">function</span> [w,rho] = mh(A)
<span class="comment">% [W,RHO] = MH(A) gives a vector of the Metropolis-Hastings edge weights</span>
<span class="comment">% for a graphb described by the incidence matrix A (NxM). N is the number</span>
<span class="comment">% of nodes, and M is the number of edges. Each column of A has exactly one</span>
<span class="comment">% +1 and one -1. RHO is computed from the weights W as follows:</span>
<span class="comment">%    RHO = max(abs(eig( eye(n,n) - (1/n)*ones(n,n) - A*W*A' ))).</span>
<span class="comment">%</span>
<span class="comment">% The M.-H. weight on an edge is one over the maximum of the degrees of the</span>
<span class="comment">% adjacent nodes.</span>
<span class="comment">%</span>
<span class="comment">% For more details, see the references:</span>
<span class="comment">% "Fast linear iterations for distributed averaging" by L. Xiao and S. Boyd</span>
<span class="comment">% "Fastest mixing Markov chain on a graph" by S. Boyd, P. Diaconis, and L. Xiao</span>
<span class="comment">% "Convex Optimization of Graph Laplacian Eigenvalues" by S. Boyd</span>
<span class="comment">%</span>
<span class="comment">% Almir Mutapcic 08/29/06</span>

<span class="comment">% degrees of the nodes</span>
[n,m] = size(A);
Lunw = A*A';          <span class="comment">% unweighted Laplacian matrix</span>
degs = diag(Lunw);

<span class="comment">% Metropolis-Hastings weights</span>
mh_degs = abs(A)'*diag(degs);
w = 1./max(mh_degs,[],2);

<span class="comment">% compute the norm</span>
<span class="keyword">if</span> nargout &gt; 1,
    rho = norm( eye(n) - A*diag(w)*A' - (1/n)*ones(n) );
<span class="keyword">end</span>
</pre>
</div>
</body>
</html>